<template>
  <div>
    <div class="courses-nav jx-content">
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item label="题目类型 :">
          <el-select v-model="questionTypeMessage" placeholder="请选择" @change="getTopicModel">
            <el-option v-for="(item,index) in questionTypeList" :key="index" :label="item.message" :value="item.type"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="试题章节 :">
          <el-select :clearable="false" v-model="chapterMessage" placeholder="请选择" @change="getchapterModel">
            <el-option v-for="(item,index) in chapterList" :key="index" :label="item.chapterName" :value="item.chapterId"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </div>
    <router-view></router-view>
  </div>
</template>
<script>
import axios from "axios";
import $ from "jquery";
export default {
  data() {
    return {
      searchForm: {
        //当前页
        pageNum: 1,
        //每页显示条数
        //pageSize:10,
        //关键词
        keyWord: "",
        //章节id
        chapterId: 0,
        //题型序号
        questionType: 0
      },
      rowData: [],
      //题目类型名称
      questionTypeMessage: '选择题',
      //题目类型数组
      questionTypeList: [],
      //章节名称
      chapterMessage: "",
      //章节数组
      chapterList: []
    };
  },
  watch: {
    $route(to, from) {
      to.params.rowData = this.rowData;
      console.log(to, 889911);
      console.log(from, 889911);
      if (to.name == "AddQuestionLayout") {
        this.$router.push({
          path: "/Teaching/MyCourses/Examination/itemBank"
        });
      }
    },
    questionTypeMessage(val) {
      //1选择 addChoiceQuestion
      //2判断 addJudge
      //3填空 addFillInTheBlanks
      //4简答 AddShortAnswerQuestions
      //5编程 addChoiceQuestion
      //6实验 AddExperimental
      val = Number(val);
      console.log(val, 111);
      switch (val) {
        case 1:
          this.$router.push({
            path: "/Teaching/MyCourses/Examination/AddChoice/addChoiceQuestion"
          });
          break;
        case 2:
          this.$router.push({
            path: "/Teaching/MyCourses/Examination/AddChoice/addJudge"
          });
          break;
        case 3:
          this.$router.push({
            path: "/Teaching/MyCourses/Examination/AddChoice/addFillInTheBlanks"
          });
          break;
        case 4:
          this.$router.push({
            path: "/Teaching/MyCourses/Examination/AddChoice/AddShortAnswerQuestions"
          });
          break;
        case 5:
          this.$router.push({
            path: "/Teaching/MyCourses/Examination/AddChoice/addJudge"
          });
          break;
        case 6:
          this.$router.push({
            path: "/Teaching/MyCourses/Examination/AddChoice/addExperimental"
          });
          break;
        default:
          this.$router.push({
            path: "/Teaching/MyCourses/Examination/itemBank"
          });
      }
    }
  },
  mounted() {
    this.init();
  },
  methods: {
    init() {
      let that = this;
      that.getEditData();
    },
    //获取修改数据
    getEditData() {
      let rowData = this.$route.params.rowData;
      this.rowData = rowData;
      this.getTopicSelected();
      this.chapterMessage = rowData.chapterName;
      this.questionTypeMessage = rowData.questionType;
    },
    //获取题目类型和章节下拉
    getTopicSelected() {
      var that = this;
      axios
        .get("/tes/course/"+this.$localstorage.getLocalStorage('setCourseId')+"/businessType/1/question-repository/dropdown-list")
        .then(function(res) {
          console.log("成功");
          console.log(res);
          if (res.status === 200) {
            if (res.data.code === 200) {
              console.log(res.message);
              //赋值题目类型
              let questionTypeList = res.data.data.questionTypeList;
              that.questionTypeList = questionTypeList;
              //赋值章节列表
              let chapterList = res.data.data.chapterList;
              that.chapterList = chapterList;
            }
          }
        })
        .catch(function(err) {
          if (err.response) {
            console.log(err.response);
          }
        });
    },

    //获取题目类型
    getTopicModel(val) {
      this.addForm.questionType = val;
      switch (val) {
        case 1:
          this.$router.push({
            path: "/Teaching/MyCourses/Examination/addChoiceQuestion"
          });
          break;
        case 2:
          this.$router.push({ path: "/Teaching/MyCourses/Examination/addJudge" });
          break;
        case 3:
          this.$router.push({
            path: "/Teaching/MyCourses/Examination/addFillInTheBlanks"
          });
          break;
        case 4:
          this.$router.push({
            path: "/Teaching/MyCourses/Examination/AddShortAnswerQuestions"
          });
          break;
        case 5:
          this.$router.push({ path: "/Teaching/MyCourses/Examination/addJudge" });
          break;
        case 6:
          this.$router.push({ path: "/Teaching/MyCourses/Examination/addExperimental" });
          break;
        default:
          console.log(1234);
      }
    },
    //获取章节
    getchapterModel(val) {
      this.searchForm.chapterId = val;
      this.$router.push({
        chapterId:val
      });
      //this.router.params.rowData = this.rowData;
      //his.$root.$emit('chapter-id',12345);
    }
  }
};
</script>


